<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>内容适应宽度</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      html,
      body {
        height: 100%;
      }
      body {
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .box {
        width: 600px;
        padding: 20px;
        border-radius: 6px;
        background-color: #ece4dd;
      }
      .parent {
        /* 宽度适应内容 */
        width: -moz-fit-content;
        width: fit-content;
        padding: 20px;
        border-radius: 6px;
        background-color: #2c4465;
      }
      .child {
        font-size: 18px;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="parent">
        <span class="child">width: -moz-fit-content; width: fit-content;</span>
      </div>
    </div>
  </body>
</html>
